package com.example.backend.service;

import com.example.backend.common.utils.RedisUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * Token黑名单服务
 */
@Service
@RequiredArgsConstructor
public class TokenBlacklistService {
    
    private final RedisUtils redisUtils;
    private static final String TOKEN_BLACKLIST_PREFIX = "token:blacklist:";
    
    /**
     * 将Token加入黑名单
     */
    public void addToBlacklist(String token, long expiration) {
        String key = TOKEN_BLACKLIST_PREFIX + token;
        redisUtils.set(key, "", expiration, TimeUnit.MILLISECONDS);
    }
    
    /**
     * 判断Token是否在黑名单中
     */
    public boolean isBlacklisted(String token) {
        return redisUtils.hasKey(TOKEN_BLACKLIST_PREFIX + token);
    }
} 